package cn.wsalix.observable.service.impl;

import java.util.Observable;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.wsalix.observable.service.PayService;
import cn.wsalix.order.entity.Order;
import cn.wsalix.order.form.WeiXinNotifyForm;
import cn.wsalix.order.service.OrderInfoService;
import cn.wsalix.order.service.OrderService;
import cn.wsalix.order.service.TuanService;
import cn.wsalix.user.service.MineService;

@Service("payService")
public class PayServiceImpl extends Observable implements PayService {
	protected Logger logger = LoggerFactory.getLogger(getClass());
	@Autowired
	private OrderService orderService;
	@Autowired
	private OrderInfoService orderInfoService;
	@Autowired
	private TuanService masterTuanService;
	@Autowired
	private MineService myProductService;
	private Order order;
	private boolean treate;
	@PostConstruct
	public void init() {
		logger.info("==========init");
		addObserver(myProductService);
		addObserver(masterTuanService);
		addObserver(orderInfoService);
		addObserver(orderService);
	}

	@PreDestroy
	public void destroy() {
		logger.info("==========destroy");
	}
	@Transactional
	@Override
	public Order weiXinPay(WeiXinNotifyForm entity) {
		setChanged();
		notifyObservers(entity);
		orderService.edit(order);
		return order;
	}

	public Order getOrder() {
		return order;
	}

	public void setOrder(Order order) {
		this.order = order;
	}

	@Override
	public boolean isTreate() {
		return treate;
	}

	public void setTreate(boolean treate) {
		this.treate = treate;
	}

}
